package com.hugang.juc.assistclass;

import java.util.concurrent.CountDownLatch;

/**
 * 闭锁，类似于倒数的计数器
 *
 * @author hg
 * @date 2020/8/20 16:12
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName() + " ---> 离开了教室");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        countDownLatch.await();
        System.out.println("锁门");
    }
}
